<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
 
<form class="layui-form" action="www.baidu.com" style="margin: 40px 100px 10px 20px;">
	<div class="layui-form-item">
	  <label class="layui-form-label">评分:</label>
	  <div class="layui-input-block">
			<div id="test2"></div>
	  </div>
	</div>
	
  <div class="layui-form-item">
    <label class="layui-form-label">评价:</label>
    <div class="layui-input-block">
      <textarea lay-verify="title" id="acomment" placeholder="请输入内容" class="layui-textarea" style="width: 400px;"></textarea>
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="demo1" style="background-color: #337AB7;color: white;margin-left: 35%;">立即提交</button>
    </div>
  </div>
</form>
          
<script src="layui/layui.all.js" charset="utf-8"></script>
<script src="layui/jquery.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
var val=5;
var form = layui.form,layer = layui.layer,layedit = layui.layedit,laydate = layui.laydate;
layui.use(['form', 'layedit', 'laydate'], function(){
  
  //创建一个编辑器
  var editIndex = layedit.build('LAY_demo_editor');
  
//自定义验证规则
  form.verify({
    title: function(value){
      if(/[@#$%^&*<>]+/.test(value)){        
          return '不能出特殊字符';
      }
      if(!/[@#\$%\^&\*]+/.test(value)){        
          return '不能出现空格';
      }
      if(value.length < 4){
          return '内容不能少于五个字符';
        }
    }
  
  });
  
  //监听提交
  form.on('submit(demo1)', function(data){
    $.ajax({
		url:"/cinema/addComment",
		type:"post",
		async: false,
		data:{
			agrade:val,
			acomment:$('#acomment').val()
		},
		success:function(data){
			if(data=="评论成功"){
				alert(data);
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);	
				
			}else if(data=="请先登录!"){
				alert(data);
				location.href="";
			}
			location.reload();
		}
})
  });
  
});

  
layui.use(['rate'], function(){
  var rate = layui.rate;
  //基础效果
  rate.render({
    elem: '#test1'
  })
 
  //显示文字
  rate.render({
    elem: '#test2'
    ,value: 5 //初始值
    ,half: true //开启半星
    ,text: true //开启文本
    ,choose: function(value){
    	val=value;
    }
  });

});


</script>

</body>
</html>
